<template>
  <div class="logistic" @click.stop="handleChange">
    <div class="left">
      <img v-if="isChecked" src="@/assets/addstart/setinfo/checkbox_true.png" />
      <img v-else src="@/assets/addstart/setinfo/checkbox_false.png" />
    </div>

    <div class="center">
      <div class="c-title">{{ itemData.place_name }}</div>

      <div class="c-info">
        <span>{{ itemData.contact_person }}</span>
        <span>{{ itemData.phone }}</span>
      </div>

      <div class="c-address">
        {{ itemData.city_province + itemData.detail_address }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { computed } from 'vue'
  import { ref } from 'vue'

  // ------ props
  interface IProps {
    itemData: any
  }
  const props = defineProps<IProps>()

  // ------ data
  const isChecked = ref<boolean>(false)

  // ------ computed
  const checkedItemCpt = computed(() => {
    return { id: props.itemData.id, isChecked: isChecked.value }
  })

  // ------ methods
  const handleChange = () => {
    isChecked.value = !isChecked.value
  }

  // ------ lifecycle
  function setupInit() {
    const localLogisticIdArr = window.localStorage.getItem('logisticIdArr')
    if (localLogisticIdArr) {
      const idArr = JSON.parse(localLogisticIdArr)
      const findItem = idArr.find((it: any) => it == props.itemData.id)
      if (findItem) isChecked.value = true
    }
  }
  setupInit()

  // ------ expose
  defineExpose({ checkedItemCpt })
</script>

<style lang="scss" scoped>
  .logistic {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0 30px;
    width: 100%;
    height: 224px;
    background: #ffffff;
    border-radius: 20px;
    overflow: hidden;
    margin-top: 20px;

    .left {
      display: flex;
      align-items: center;
      width: 70px;

      img {
        display: block;
        width: 36px;
      }
    }

    .center {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      height: 100%;

      .c-title {
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 42px;
      }

      .c-info {
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #000000;
        line-height: 34px;
        margin: 17px 0 4px 0;

        span:first-of-type {
          margin-right: 40px;
        }
      }

      .c-address {
        width: 482px;
        // height: 68px;
        max-height: 68px;
        font-size: 24px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        line-height: 34px;

        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
      }
    }
  }
</style>
